$(function(){
	$('body').delegate(".ajax_del",'click',function(){
		var url = $(this).attr("href");
		$.confirm("确认删除该条记录吗？",function(){
			$.ajax({
				url:url,
				type:"get",
				success:function(obj){
					console.log(obj);
					if (typeof(obj)!=Object) {
						obj = eval("("+obj+")");
					}
					$.alert(obj.errmsg,function(i){
						location.reload();
					});
				},
				error:function(e){
					console.log(e);
					$.alert("网络超时或未知错误，请稍后重试！");
				}
			});
		});
		return false;
	});
	$('body').delegate(".ajax_submit",'submit',function(){
		var url = $(this).attr("action");
		var back = $(this).attr("back");
		$.ajax({
			url:url,
			type:"post",
			data:$(this).serialize(),
			success:function(obj){
				console.log(obj);
				if (typeof(obj)!=Object) {
					obj = eval("("+obj+")");
				}
				$.alert(obj.errmsg,function(i){
					if(obj.errcode==0){
						if(back == "true"){
							self.location=document.referrer;
						}else{
							location.reload();
						}
					}
					//重新设置令牌数据
					else if(obj.errcode==-1003){
						$("input[name='hash']").val(obj.__hash__);
					}
				});
			},
			error:function(e){
				console.log(e);
				$.alert("网络超时或未知错误，请稍后重试！");
			}
		});
		return false;
	});
	
	$('body').delegate(".layer-open",'click',function(){
		var url = $(this).attr("href");
		var area = $(this).attr("layer-area");
		var areaObj = area.split(",");
		var title = $(this).attr("layer-title")?$(this).attr("layer-title"):"";
		layer.open({
			title:title,
			type:2,
			closeBtn:false,
			shadeClose:true,
			area:[areaObj[0],areaObj[1]],
			content:url
		});
		return false;
	});
	
	
});